package com.hxkj.controller;


import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.DictType;
import com.hxkj.service.DictTypeService;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;


/**
 * 一级字典列表 服务层
 * <p>
 * Created by zzx on 2018/5/15.
 */
@RestController
@RequestMapping("/dictType")
public class DictTypeController {


    @Autowired
    private DictTypeService dictTypeService;

    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<PageInfo<DictType>> getList(@ModelAttribute DictType dictType, @ModelAttribute PageTo pageParam) throws Exception {
        return () -> dictTypeService.getDictTypeList(dictType == null ? new DictType() : dictType, pageParam);
    }


    /**
     * 获取字典分类
     *
     * @param dictType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<DictType> getDictTypeFromCache(@ModelAttribute DictType dictType) {
        return () -> dictTypeService.getDictTypeFromCache(dictType);
    }

    /**
     * 新增字典
     *
     * @param dictType 字典信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void saveDictItem(@ModelAttribute DictType dictType) throws Exception {
        dictTypeService.saveDictType(dictType);
    }

    /**
     * 删除字典
     *
     * @param dictType 字典
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public void deleteDictItem(@ModelAttribute DictType dictType) throws Exception {
        dictTypeService.deleteDictType(dictType);
    }

    /**
     * 修改字典
     *
     * @param dictType 字典信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public void updateDictItem(@ModelAttribute DictType dictType) throws Exception {
        dictTypeService.updateDictType(dictType);
    }


    /**
     * 禁用一个 一级 字典
     * @param dictType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public void modifyDictType(@ModelAttribute DictType dictType) throws Exception{
       dictTypeService.modifyDictType(dictType);
    }


}
